﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Shoozla.ViewModel;
using Shoozla.View;

namespace Shoozla
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
            DataContext = new MainWindowViewModel();
        }

        public void InitProgressBar(int max, string action)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                statusPB.Maximum = max;
                statusPB.Minimum = 0;
                countTB.Visibility = System.Windows.Visibility.Visible;

                switch (App.CurrenAppStatus)
                {
                    case App.AppStatus.ReadingFiles: { progressBarTaskBar.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal; break; }
                    case App.AppStatus.SearchingCovers: { progressBarTaskBar.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Paused; break; }
                    case App.AppStatus.ApplyingCovers: { progressBarTaskBar.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error; break; }
                }

               // statusTB.Text = action;
                countTB.Text = statusPB.Minimum + "/" + statusPB.Maximum;
                if (max == 0)
                    StopProgressBar();
            })
           );
        }

        public void IncrementBar()
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                statusPB.Value++;
                countTB.Text = statusPB.Value + "/" + statusPB.Maximum;
                  

                double  singleIncrement = (100/statusPB.Maximum) * 0.01;
                progressBarTaskBar.ProgressValue += singleIncrement; // X:1=100:MAX --> percentage of increment
                if (statusPB.Value >= statusPB.Maximum)
                    StopProgressBar();
            })
           );
        }

        public void StopProgressBar()
        {
            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                progressBarTaskBar.ProgressValue = 0;
                statusPB.IsIndeterminate = false;
                statusPB.Value = statusPB.Minimum;
                countTB.Visibility = System.Windows.Visibility.Collapsed;
            })
            );
        }
    }
}
